*** Settings ***
Documentation    TC01-Create a new FCL Project
Resource    ../../Keywords/Common_Head.robot
Force Tags    P1
Metadata    Author    Momo
Metadata    ID    6850886


*** Test Cases ***
TC01-Create a new FCL Project
    Step 1 User Goes To Basic Data Management Tender List
    Step 2 User Goes To Pricing Collaboration Pricing Project
    Step 3 User inputs Tender ID created in step1 in the Tender ID
    Step 4 User Chooses The Step 1 Tender From The Dropdown
    Step 5 User Clicks Dropdown List From Mode Field
    Step 6 User Chooses FCL From The Dropdown List
    Step 7 User Selects The current Date 10 11 30 00 For Deadline
    Step 8 User Selects The current Date For Rate Validity From
    Step 9 User Clicks Deputy Button
    Step 10 User Inputs MARYMA01 In The SIMS ID Field Clicks Search
    Step 11 User Clicks Select Button
    Step 12 User Clicks Upload Button Add File Button In The Upload
    Step 13 User Checks The Information At The Bottom Of This
    Step 14 User Clicks Save Button
    Step 15 User Selects TenderID Created TenderID In Step 1
    Step 16 Select This Project Click On Delete Project Button
    Step 17 User Goes To Basic Data Management Tender List 2



*** Keywords ***
Step ${step} User Goes To Basic Data Management Tender List
    #************************Step 1******************************
    #  Do:
    #      User goes to Basic Data Management Tender List
    #      Click Create button
    #      Input with following attributes
    #      Tender ID some numbers such as 202408151435001 you can
    #     input with current datetime and some random number to
    #     avoid duplicate validation
    #      Tender Title some value such as Regression Test by
    #     Wendy001
    #      Customer 815 Miele
    #      Mode select all
    #      Level Global
    #      Click on Save button
    #  Expected:
    #      Created successfully with the message Tender has been
    #     added
    #************************************************************
    ${G_TENDERID}    Generate Tender ID
    ${TenderTitle}   Set Variable    Regression Test by auto
    Set Suite Variable     ${G_TENDERID}
    Login Space
    Create Tender    ${G_TENDERID}    ${TenderTitle}    815    true    true    true
    ${PROJECT}    Copy Dictionary    ${PROJECT_PARAM}
    Set To Dictionary    ${PROJECT}
    ...    TENDER_ID=${G_TENDERID}    TENDER_TITLE=${TenderTitle}    CUSTOEMR_NAME=Miele    CUSTOMER_LEVEL=Global
    ...   MODE=FCL    DEPUTY=SNOWLI01    TEMPLATE=${CURDIR}${/}TestData${/}FCLTemplate-Location-All.xlsx
    Set Suite Variable     ${PROJECT}

Step ${step} User Goes To Pricing Collaboration Pricing Project
    #************************Step 2******************************
    #  Do:
    #      User goes to Pricing Collaboration Pricing Project
    #      User clicks Create Project button
    #  Expected: 
    #      A New Project dialog should be opened successfully
    #************************************************************
    Wait Until Keyword Succeeds    5x    100ms    Click   ${navigation_pricing_project}
    Wait For Elements State    ${Project_toolbar_CreateButton}    visible    10
    Wait Until Search Finished
    Wait Until Keyword Succeeds    5x    100ms    Click    ${Project_toolbar_CreateButton}
    Wait For Elements State   ${Project_create_TenderID}     enabled

Step ${step} User inputs Tender ID created in step1 in the Tender ID
    #************************Step 3******************************
    #  Do:
    #      User inputs Tender ID created in step1 in the Tender ID field.
    #     field
    #  Expected:
    #      	A dropdown list 'step 1 Tender ID' comes up.
    #************************************************************
    Fill Text    ${Project_create_TenderID}    ${PROJECT.TENDER_ID}
    Sleep    1
    Wait For Elements State    ${Project_create_TenderIdDropDown}    visible    60
    Wait Until Search Finished

Step ${step} User Chooses The Step 1 Tender From The Dropdown
    #************************Step 4******************************
    #  Do:
    #      User chooses the step 1 Tender from the dropdown list.
    #  Expected:
    #      Customer field should be fulfilled with Miele
    #      Vertical Market should be Consumer
    #      Level should be fulfilled with Global
    #************************************************************
    Click    ${Project_create_TenderIdDropDown}
    Wait Until Keyword Succeeds    5x    200ms    Check Text Value    ${Project_create_ProjectName}    ${PROJECT.TENDER_ID}-undefined-${PROJECT.TENDER_TITLE}
    Check Text Value    ${Project_create_Customer}    ${PROJECT.CUSTOEMR_NAME}
    Check Text Value    ${Project_create_Level}    ${PROJECT.CUSTOMER_LEVEL}

Step ${step} User Clicks Dropdown List From Mode Field
    #************************Step 5******************************
    #  Do:
    #      User clicks dropdown list from Mode field
    #  Expected:
    #      There should be mode FCL from the dropdown list
    #************************************************************
    Get Select Options    select[id='mode']    validate    [v["label"] for v in value] == ["--please select a mode--","AIR", "FCL", "LCL"]

Step ${step} User Chooses FCL From The Dropdown List
    #************************Step 6******************************
    #  Do:
    #      User chooses FCL from the dropdown list
    #  Expected:
    #      The project Name field should be changed to be 20240815
    #     FCL Regression
    #************************************************************
    Select Options By   ${Project_create_Mode}    label    ${PROJECT.MODE}
    Check Text Value    ${Project_create_ProjectName}    ${PROJECT.TENDER_ID}-${PROJECT.MODE}-${PROJECT.TENDER_TITLE}

Step ${step} User Selects The current Date 10 11 30 00 For Deadline
    #************************Step 7******************************
    #  Do:
    #      User selects the current date 10 11 30 00 for Deadline
    #     to TM field
    #  Expected:
    #      The current date 10 11 30 00 should be input
    #     successfully
    #************************************************************
    ${DEADLINE_TM_DATE}    Get Current Date    UTC    +10days    result_format=%d/%m/%Y
    Fill Text    ${Project_create_DeadlinetoTMDate}    ${DEADLINE_TM_DATE}

Step ${step} User Selects The current Date For Rate Validity From
    #************************Step 8******************************
    #  Do:
    #      User selects the current date for Rate Validity From
    #      User selects the current date 30 for Rate Validity To
    #  Expected:
    #      They both should be input successfully
    #************************************************************
    IF    '${project_param.VALID_FROM}'=='DEFAULT'
           ${CurDate}    Get Current Date    result_format=%d/%m/%Y
           ${FutureDate}    Get Current Date    UTC    +30days    result_format=%d/%m/%Y
           Set To Dictionary    ${project_param}    VALID_FROM=${CurDate}    VALID_TO=${FutureDate}
    END
    Fill Text    ${Project_create_RateValidityFrom}    ${project_param.VALID_FROM}
    Fill Text    ${Project_create_RateValidityTo}   ${project_param.VALID_TO}

Step ${step} User Clicks Deputy Button
    #************************Step 9******************************
    #  Do:
    #      User clicks Deputy button
    #  Expected:
    #      The User locator dialog should be opened
    #************************************************************
    Wait Until Keyword Succeeds    5x    300ms    Click    ${Project_create_Deputies}

Step ${step} User Inputs MARYMA01 In The SIMS ID Field Clicks Search
    #************************Step 10******************************
    #  Do:
    #      User inputs MARYMA01 in the SIMS ID field clicks search
    #     button
    #  Expected:
    #      The MARYMA01 should be searched out
    #************************************************************
    Wait For Elements State   Select[data-ng-change="selectedCriterion(qe.id, 'simsId')"]     enabled    30
    Fill Text     css = [data-type-validation='Joose.Type.Str']    ${PROJECT.DEPUTY}
    Click    ${user_locator_search_button} 
    Wait For Elements State    xpath=//td[.='${PROJECT.DEPUTY}']    visible

Step ${step} User Clicks Select Button
    #************************Step 11******************************
    #  Do:
    #      User clicks select button
    #  Expected:
    #      The User locator dialog should be closed and MARYMA01
    #     should be added into the Deputy
    #************************************************************
    Click    xpath=//td[.='${PROJECT.DEPUTY}']
    Click    ${user_locator_selectButton} 
    Wait Until Search Finished

Step ${step} User Clicks Upload Button Add File Button In The Upload
    #************************Step 12******************************
    #  Do:
    #      User clicks upload button add file button in the Upload
    #     Template dialog choose a file
    #  Expected:
    #      The file should be uploaded successfully in the
    #     document section
    #************************************************************
    IF    '${PROJECT.TEMPLATE}'!=''
        Wait Until Keyword Succeeds    5x    300ms    Click    ${Project_create_UploadButton}
        Wait For Elements State   ${upload_addFileButton}     enabled
        Upload File By Selector    ${upload_addFileButton}    ${PROJECT.TEMPLATE}
    END

Step ${step} User Checks The Information At The Bottom Of This
    #************************Step 13******************************
    #  Do:
    #      User checks the information at the bottom of this
    #     dialog
    #  Expected:
    #      The Project Owner should be current user name SIMS ID
    #      Create Date should be current system date
    #      Status should be In Progress
    #************************************************************
    Wait For Elements State    ${Project_create_ProjectOwner}    visible
    Check Text Value    ${Project_create_ProjectOwner}    ${USERNAME_FULL}
    ${CurrentDate}    Get Current Date      result_format=%d/%m/%Y
    Check Text Value    ${Project_create_CreateDate}    ${CurrentDate}
    Check Text Value    ${Project_create_Status}    In Progress

Step ${step} User Clicks Save Button
    #************************Step 14******************************
    #  Do:
    #      User clicks save button
    #  Expected:
    #      The project should be saved at the top of the project
    #     list
    #************************************************************
    Wait Until Search Finished
    Wait Until Keyword Succeeds    5x    300ms    Click    ${Project_create_SaveButton}
    Wait Until Search Finished

Step ${step} User Selects TenderID Created TenderID In Step 1
    #************************Step 15******************************
    #  Do:
    #      User selects TenderID Created TenderID In Step 1
    #  Expected:
    #      The project could be found
    #************************************************************
    Search Project    ${G_TENDERID}

Step ${step} Select This Project Click On Delete Project Button
    #************************Step 16******************************
    #  Do:
    #      Select this project click on Delete Project button
    #      Click Yes of the pop up confirm window
    #  Expected:
    #      System displays Project has been deleted
    #************************************************************
    Delete Project    ${G_TENDERID}

Step ${step} User Goes To Basic Data Management Tender List 2
    #************************Step 17******************************
    #  Do:
    #      User goes to Basic Data Management Tender List
    #      Search out the tender created in step1
    #      Click on Delete button
    #      Click on Yes button in the popup dialog
    #  Expected:
    #      System displays Tender has been deleted
    #************************************************************
    Delete Tender    ${G_TENDERID}

